Eventstore API
Based on
Usage
Reading a stream:
async function listTransactionHistory(transactionId: string, eventSource: EventSource): Promise<{timestamp: Date, data: Transaction}> {
return lastValueFrom(
eventSource.streamReader.readStreamForwards({category: "transaction", id: transactionId})
.pipe(toArray(), map(re => ({timestamp: re.event.timestamp, data: re.event.data as Transaction})))
)
}
Reading entire store:
return new Promise(((resolve, reject) => {
let lastPosition = position
eventSource.storeReader.readAll(position).subscribe(
re => {
ingestTransaction(re.event.data as Transaction)
lastPosition = re.position
},
err => reject("Failed to read all transactions since " + lastPosition + ": " + err),
() => resolve(lastPosition)
)
}))
Code Formatting with Prettier
Recommend you use prettier
for formatting so that we have a consistent code style.
If you are using IntelliJ then install the Prettier plugin. You can config it to run when you normally run format (see
Languages & Frameworks > Javascript > Prettier
and check "Run on 'Reformat Code' action")